package com.glamour.hlcity.component.upload.util;

import java.io.File;
import java.io.IOException;
import java.util.Calendar;

import org.apache.commons.io.FileUtils;

/***
 * 文件工具
 * @author zhaoxing.liuzx
 *
 */
public class FileUtil {
	
	/**
	 * 附件主目录
	 */
	public final static String UPLOAD_DIR="upload\\";
	
	/**
	 * 将文件进行拷贝
	 * @param srcFile
	 * @param destFile
	 * @throws IOException 
	 */
	public static void copyFile(File srcFile,File destFile) throws IOException {
		FileUtils.copyFile(srcFile, destFile);
	}
	
	/**
	 * 文件大小
	 * @param file
	 * @return
	 */
	public static Long size(File file){
		return FileUtils.sizeOf(file);
	}
	
	/**
	 * 新建一个目录
	 * @param fileDir
	 * @throws IOException
	 */
	public static void mkdir(String fileDir) throws IOException{
		File directory=new File(fileDir);
		FileUtils.forceMkdir(directory);
	}
	
	/**
	 * 默认目录
	 * @return
	 */
	public static String createDir(){
		Calendar cal=Calendar.getInstance();
		String year=String.valueOf(cal.get(Calendar.YEAR));
		String month=String.valueOf(cal.get(Calendar.MONTH)+1);
		String day=String.valueOf(cal.get(Calendar.DAY_OF_MONTH));
		return UPLOAD_DIR.concat(year).concat("\\").concat(month).concat("\\").concat(day).concat("\\");
	}
	
	
	
	
	
}
